home *** CD-ROM | disk | FTP | other *** search
/ Aminet 6 / Aminet 6 - June 1995.iso / Aminet / gfx / 3d / irit50src.lha / irit5 / grapdrvs / drawtriv.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-19  |  4.4 KB  |  125 lines

  1. /*****************************************************************************
  2. *   Default surface drawing routine common to graphics drivers.             *
  3. *                                         *
  4. * Written by:  Gershon Elber                Ver 0.1, June 1993.  *
  5. *****************************************************************************/
  6.  
  7. #include "irit_sm.h"
  8. #include "iritprsr.h"
  9. #include "allocate.h"
  10. #include "attribut.h"
  11. #include "cagd_lib.h"
  12. #include "symb_lib.h"
  13. #include "ip_cnvrt.h"
  14. #include "iritgrap.h"
  15.  
  16. /*****************************************************************************
  17. * DESCRIPTION:                                                               M
  18. * Draw a single trivariate function object using current modes and          M
  19. * transformations.                                 M
  20. *   Piecewise linear approximation is cashed under "_isoline" and "_ctlmesh" M
  21. * attributes of PObj. Polygonal approximation is saved under "_polygons".    M
  22. *                                                                            *
  23. * PARAMETERS:                                                                M
  24. *   PObj:     A trivariate function object to draw.                          M
  25. *                                                                            *
  26. * RETURN VALUE:                                                              M
  27. *   void                                                                     M
  28. *                                                                            *
  29. * KEYWORDS:                                                                  M
  30. *   IGDrawTrivar                                                             M
  31. *****************************************************************************/
  32. void IGDrawTrivar(IPObjectStruct *PObj)
  33. {
  34.     IPObjectStruct *PObjPolylines, *PObjCtlMesh, *PObjPolygons;
  35.     IPPolygonStruct *PPolylines, *PCtlMesh, *PPolygons, *PPolygonTemp;
  36.  
  37.     if ((PObjPolylines = AttrGetObjectObjAttrib(PObj, "_isoline")) == NULL &&
  38.     IGGlblNumOfIsolines > 0) {
  39.     TrivTVStruct *TV,
  40.         *TVs = PObj -> U.Trivars;
  41.  
  42.     PObjPolylines = IPAllocObject("", IP_OBJ_POLY, NULL);
  43.     PObjPolylines -> Attrs = AttrCopyAttributes(PObj -> Attrs);
  44.     IP_SET_POLYLINE_OBJ(PObjPolylines);
  45.     for (TV = TVs; TV != NULL; TV = TV -> Pnext) {
  46.         int NumOfIso[3],
  47.         Res = MAX(IGGlblNumOfIsolines / 2, 2);
  48.  
  49.         NumOfIso[0] = -Res;
  50.         NumOfIso[1] = -Res;
  51.         NumOfIso[2] = -Res;
  52.         PPolylines = IritTrivar2Polylines(TV, NumOfIso,
  53.                           IGGlblSamplesPerCurve,
  54.                           IGGlblPolylineOptiApprox);
  55.  
  56.         if (PPolylines != NULL) {
  57.         for (PPolygonTemp = PPolylines;
  58.              PPolygonTemp -> Pnext;
  59.              PPolygonTemp = PPolygonTemp -> Pnext);
  60.         PPolygonTemp -> Pnext = PObjPolylines -> U.Pl;
  61.         PObjPolylines -> U.Pl = PPolylines;
  62.         }
  63.     }
  64.     AttrSetObjectObjAttrib(PObj, "_isoline", PObjPolylines, FALSE);
  65.     }
  66.  
  67.     if (IGGlblDrawSurfacePoly || IGGlblDrawSolid) {
  68.     if ((PObjPolygons = AttrGetObjectObjAttrib(PObj, "_polygons"))
  69.                                     == NULL) {
  70.         TrivTVStruct *TV,
  71.         *TVs = PObj -> U.Trivars;
  72.  
  73.  
  74.         PObjPolygons = IPAllocObject("", IP_OBJ_POLY, NULL);
  75.         PObjPolygons -> Attrs = AttrCopyAttributes(PObj -> Attrs);
  76.         IP_SET_POLYGON_OBJ(PObjPolygons);
  77.  
  78.         for (TV = TVs; TV != NULL; TV = TV -> Pnext) {
  79.         PPolygons = IritTrivar2Polygons(TV, IGGlblFourPerFlat,
  80.                         IGGlblFineNess, FALSE,
  81.                         IGGlblPolygonOptiApprox);
  82.  
  83.         if (PPolygons != NULL) {
  84.             if (PPolygons) {
  85.             for (PPolygonTemp = PPolygons;
  86.                  PPolygonTemp -> Pnext;
  87.                  PPolygonTemp = PPolygonTemp -> Pnext);
  88.             PPolygonTemp -> Pnext = PObjPolygons -> U.Pl;
  89.             PObjPolygons -> U.Pl = PPolygons;
  90.             }
  91.         }
  92.         }
  93.         AttrSetObjectObjAttrib(PObj, "_polygons", PObjPolygons, FALSE);
  94.     }
  95.  
  96.     IGDrawPoly(PObjPolygons);
  97.     }
  98.     else if (PObjPolylines != NULL)
  99.         IGDrawPoly(PObjPolylines);
  100.  
  101.     if (IGGlblDrawSurfaceMesh) {
  102.     if ((PObjPolylines = AttrGetObjectObjAttrib(PObj, "_ctlmesh"))
  103.                                 == NULL) {
  104.         TrivTVStruct *TV,
  105.         *TVs = PObj -> U.Trivars;
  106.  
  107.         PObjCtlMesh = IPAllocObject("", IP_OBJ_POLY, NULL);
  108.         PObjCtlMesh -> Attrs = AttrCopyAttributes(PObj -> Attrs);
  109.         IP_SET_POLYLINE_OBJ(PObjCtlMesh);
  110.         for (TV = TVs; TV != NULL; TV = TV -> Pnext) {
  111.         PCtlMesh = IritTrivar2CtlMesh(TV);
  112.  
  113.         for (PPolygonTemp = PCtlMesh;
  114.              PPolygonTemp -> Pnext;
  115.              PPolygonTemp = PPolygonTemp -> Pnext);
  116.         PPolygonTemp -> Pnext = PObjCtlMesh -> U.Pl;
  117.         PObjCtlMesh -> U.Pl = PCtlMesh;
  118.         }
  119.         AttrSetObjectObjAttrib(PObj, "_ctlmesh", PObjCtlMesh, FALSE);
  120.     }
  121.  
  122.     IGDrawPoly(AttrGetObjectObjAttrib(PObj, "_ctlmesh"));
  123.     }
  124. }
  125.